package HLLib.control.HLButton;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLImage;
import HLLib.base.HLString;

public class HLImageButton extends HLIButton {
    private HLImage image;

    private HLImage imageText;

    private HLImage imageSelected;

    public String text = null;

    //

    public int imageTrans;

    public int imagePosStyle = HCENTER_VCENTER;

    public int textcolor = 0xff000000;

    public int selectColor = 0xfffffffe;

    public boolean isSelected = false;

    public int fontFace = Font.FACE_SYSTEM;

    public int fontStyle = Font.STYLE_BOLD;

    public int fontSize = Font.SIZE_MEDIUM;

    public int type = 0;

    public HLImageButton() {

    }

    public void Init(HLImage img) {
        image = img;
        width = (short) image.GetWidth();
        height = (short) image.GetHeight();
    }

    public HLImageButton(int type, Image image) {
        this.type = (byte) type;
        this.image = new HLImage(image);
    }

    public HLImageButton(Image image, Image imageSelected, String text) {
        this(image, imageSelected);
        this.text = text;
    }

    public HLImageButton(Image image, Image imageSelected) {

        this.image = new HLImage(image);
        this.imageSelected = new HLImage(imageSelected);
        width = (short) image.getWidth();
        height = (short) image.getHeight();
    }

    public HLImageButton(Image image, Image imageSelected, Image imgText) {
        this.image = new HLImage(image);
        this.imageSelected = new HLImage(imageSelected);
        width = (short) image.getWidth();
        height = (short) image.getHeight();
        this.imageText = new HLImage(imgText);
    }

    public HLImageButton(Image image, String text) {
        this.image = new HLImage(image);
        width = (short) image.getWidth();
        height = (short) image.getHeight();
        this.text = text;
    }

    public void Logic() {
        super.Logic();
        if (!(isResponseWhole || IsFocus()) && isSelected) {
            RefreshEventKey(GetScreenX(), GetScreenY(), responseKeys);
        }
    }

    public void Render(HLGraphics g) {
        int screenX = GetScreenX();
        int screenY = GetScreenY();
        int color = textcolor;
        if (IsFocus() || isSelected) {
            color = selectColor;
            if (imageSelected == null) {

                g.DrawImageAdjustable(image, screenX, screenY, width, height, imageTrans, imagePosStyle);
            } else {
                g.DrawImageAdjustable(imageSelected, screenX, screenY, width, height, imageTrans, imagePosStyle);
            }
        } else {
            g.DrawImageAdjustable(image, screenX, screenY, width, height, imageTrans, imagePosStyle);
        }
        if (text != null) {
            g.DrawStringAdjustable(new HLString(text), color, 0, screenX, screenY, width, height, TEXT_STYLE_NORMAL, HCENTER_VCENTER);
        }
        if (imageText != null) {
            g.DrawImageAdjustable(imageText, screenX, screenY, width, height, imageTrans, HCENTER_VCENTER);
        }
    }

    public void SetFont(int face, int style, int size) {
        fontFace = face;
        fontStyle = style;
        fontSize = size;
    }

    public void Refresh() {
    }

    public void UnLoad() {
    }

}
